package com.s3_boot_mp.controller;

import com.s3_boot_mp.pojo.SysUser;
import com.s3_boot_mp.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Resource
    UserService userService;

    @RequestMapping({"/","/login","/Login","/toLogin"})
    public String login(){
        return "login";
    }

    @RequestMapping("/doLogin")
    public String login(String usrName, String password, Model model, HttpSession session){
        SysUser user= userService.login(usrName,password);
        if (null!=user){
            session.setAttribute("loginUser",user);
            return "main";
        }else{
            model.addAttribute("msg","账密错误");
            return "/WEB-INF/jsp/login.jsp";
        }
    }
    @RequestMapping("/main")
    public String main(){
        return "main";
    }
}
